package personal.wang.proxy;

import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxy {
    public static void main(String[] args) {
//        Factory factory = new Factory();
        Robot robot = new Robot();


        ResourceManagerGatway resourceManagerGatway = (ResourceManagerGatway)Proxy.newProxyInstance(
                DynamicProxy.class.getClassLoader()
                , new Class[]{Salable.class , Walkable.class, Cookable.class , ResourceManagerGatway.class}
                , new InvocationHandler() {
                    Object resourcemanager ;
                    // ActorRef
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("启动");
                        method.invoke(robot, args);
                        //
//                        method.invoke(resourcemanager , args);
//                        Method method1 = resourcemanager.getClass().getMethod("", args);
                        // actorRedd.tell(InvocationRequest(method_name , args))
                        System.out.println("停止");
                        return null;
                    }
                }

        );
        resourceManagerGatway.requestResurce();
        // JobMaster ---name , args ---->  ActorRef ->  resourceManager.clas.getMethod(name , args)
        // pekko
    }
    public static interface ResourceManagerGatway{
        void requestResurce();
    }
}
